using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

namespace CSSg2Help
{
    public class Account
    {
        public string accountName = "";
        public string parent = "";
        public string password = "";
        public string host = "";
        public string serverId = "";
        private Boolean check = false;
        public Account(string accountInfo)
        {
            MatchCollection mc = Regex.Matches(accountInfo, @"[^;]+");
            if (mc.Count != 5)
            {
                return;
            }
            this.accountName = mc[0].ToString();
            this.parent = mc[1].ToString();
            this.password = mc[2].ToString();
            this.host = mc[3].ToString();
            this.serverId = mc[4].ToString();
            check = true;
        }
        public Boolean Checked()
        {
            return check;
        }
    }
    public class AccountList
    {
        public List<Account> list = new List<Account>();
        public AccountList(string filename)
        {
            if (!File.Exists(filename))
            {
                return;
            }
            StreamReader sr = File.OpenText(filename);
            string accountInfo = "";
            while ((accountInfo = sr.ReadLine()) != null)
            {
                Account account = new Account(accountInfo);
                if (account.Checked() == true)
                {
                    list.Add(account);
                }
            }
        }
        public Account GetAccountByName(string accountName)
        {
            for (int i = 0; i < this.list.Count; i++)
            {
                if (this.list[i].accountName == accountName)
                {
                    return this.list[i];
                }
            }
            return null; 
        }
    }
}
